home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 May: Tool Chest / Developer CD Series Tool Chest (Apple Computer)(May 1999).iso / Tool Chest / Development Kits / HyperCard Related / XCMDs & XFCNs / GetVol and NewFormat / GetVol.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-10-01  |  2.8 KB  |  102 lines  |  [TEXT/MPS ]

  1. /*
  2. **        GetVol
  3. **            An XFNC that returns a list of the currently mounted volumes.
  4. **            Note the absence of robust error checking.
  5. **            GetVol returns a return delimited list of the volumes currently mounted...
  6. **
  7. **            Neil Day
  8. **            Electronic Media Group
  9. **            © Apple Computer, Inc.  1990
  10. **
  11. **            Use the following MPW commands to compile and link this...
  12. **
  13. **                c -b GetVol.c
  14. **                link -w -rt XFCN=22502 ∂
  15. **                    -m ENTRYPOINT∂
  16. **                    -sg GetVol GetVol.c.o∂
  17. **                    "{libraries}HyperXLib.o" ∂
  18. **                    "{libraries}Interface.o" ∂
  19. **                    "{Clibraries}"StdCLib.o ∂
  20. **                    "{Clibraries}"CInterface.o ∂
  21. **                    "{Clibraries}"CRuntime.o ∂
  22. **                    -o "vessel"
  23. */
  24.  
  25. #include <types.h>                                                        /* Compiler Interfaces to    */
  26. #include <resources.h>                                                    /* various managers and        */
  27. #include <files.h>                                                        /* resources ...            */
  28. #include <Packages.h>
  29. #include <String.h>
  30. #include <OSEvents.h>
  31. #include <Memory.h>
  32. #include <Events.h>
  33. #include <Errors.h>
  34. #include <Desk.h>
  35. #include <Strings.h>
  36. #include <Memory.h>
  37. #include <OSUtils.h>
  38. #include <HyperXCmd.h>
  39.  
  40. void SCopy (unsigned short pos,char *dest,char *source);                /* function prototypes        */
  41. Handle str2h (char *str);
  42.  
  43. pascal void EntryPoint (XCmdPtr paramPtr)
  44. {
  45.     HParamBlockRec block;                                    /* File manager parameter Block            */
  46.     char loadingZone[1024];                                    /* space for 31 volumes and their buds    */
  47.     char iobuffer[34];                                        /* space for volume names                */
  48.     short index = 1;                                        /* the index into the volume list        */
  49.     OSErr err = noErr;                                        /* a place for my funky errors            */
  50.     
  51.     loadingZone[0] = 0;                                        /* clear out that thar string            */
  52.  
  53.     block.fileParam.ioNamePtr = &iobuffer[0];                /* give the ioNamePtr some iobuffer        */
  54.     do {
  55.         block.volumeParam.ioVolIndex = index;                    /* set the index                    */
  56.  
  57.         err = PBHGetVInfo (&block,false);                        /* get the info on vol # index        */
  58.         if (err)
  59.             break;
  60.     
  61.         SCopy (strlen(&loadingZone[0]),&loadingZone[0],            /* slam the name into the buffer    */
  62.             p2cstr(block.fileParam.ioNamePtr));
  63.         SCopy (strlen(&loadingZone[0]),&loadingZone[0],            /* add the formating stuff            */
  64.             "\n\0");
  65.             
  66.         ++index;
  67.     
  68.     } while (true);
  69.     
  70.     paramPtr->returnValue = str2h (&loadingZone[0]);            /* set up the return values            */
  71.     
  72.     return;                                                        /* Get the flock out of here        */
  73. }
  74.  
  75. /*
  76. **        SCopy(pos,dest,source)
  77. **            Does the 'ol full service string copy thing.  Pos specifies the starting position in the 
  78. **            destination.  Whopppe.
  79. */
  80. void SCopy (pos,dest,source)
  81. unsigned short pos;
  82. char dest[],source[];
  83. {
  84.     unsigned short i=0;                                        /* normal index declaration           */
  85.     
  86.     while (dest[i+pos] = source[i]) i++;                    /* standard string copy routine       */
  87. }
  88.  
  89. /*
  90. **    str2h (str)
  91. **        copies a string into a handle and returns it
  92. */
  93. Handle str2h (str)
  94. char *str;
  95. {
  96.     Handle new;
  97.     
  98.     new = NewHandle ((long) strlen(str) + 1);
  99.     strcpy ((char *) (*new), str);
  100.     
  101.     return (new);
  102. }